﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using Moq;
using SportsStore.ServicesInterfaces;
using SportsStore.Web.Controllers;

namespace SportsStore.UnitTests.Controllers
{
  using System.Web.Mvc;

  using SportsStore.ServicesInterfaces.Interfaces;
  using SportsStore.Web.Models.Category;

  [TestFixture]
  public class NavControllerTest : BaseControllerTests
  {
    #region Setup/Teardown

    [SetUp]
    public void SetUp()
    {
      _categoryServiceMock = new Mock<ICategoryService>();
      _controller = new NavController(_categoryServiceMock.Object, null);

      _categoryServiceMock.Setup(p => p.GetCategories()).Returns(categories);
    }

    #endregion

    private Mock<ICategoryService> _categoryServiceMock;
    private NavController _controller;

    private static readonly List<string> categories = new List<string>
                                                {
                                                    "c1",
                                                    "c2",
                                                    "c3"
                                                };

    [Test]
    public void GivenANavController_WhenIGotToTheMenu_ThenItReturnsTheCorrectNumberOfCategories()
    {
      var controller = new NavController(_categoryServiceMock.Object, null);
      var result = (PartialViewResult)controller.Menu();

      var model = (CategoriesViewModel)result.Model;

      Assert.That(model.Categories.Count, Is.EqualTo(categories.Count));
    }

    [Test]
    public void GivenANavController_WhenIGoToTheMenu_ThenItReturnsTheCorrectView()
    {
      var controller = new NavController(_categoryServiceMock.Object, null);
      var result = (PartialViewResult)controller.Menu();
      
      Assert.That(result, Is.TypeOf<PartialViewResult>());
    }

    [Test]
    public void GivenANavController_WhenISelectACategory_ThenTheCorrectCategoryIsViewed()
    {
      var controller = new NavController(_categoryServiceMock.Object, null);
      var result = (PartialViewResult)controller.Menu("c1");

      var model = (CategoriesViewModel)result.Model;

      Assert.That(model.CurrentCategory, Is.EqualTo("c1"));
    }
  }
}
